<template>
  <a-row type="flex" style="flex-flow: inherit;">
    <a-col :flex="toggle ? '260px' : '30px'" style="margin-right: 12px;background-color: #fff;">
      <depart-tree :rootOpened="true" :multi="false" @ok="getTreeData" @toggleBool="toggleBool" />
      <!-- <groups-tree @tree="getTreeData" @selectedKeys="getSelectedKeys" /> -->
    </a-col>
    <a-col flex="auto">
      <a-card :bordered="false" style="margin-bottom: 10px">
        <!-- 查询区域 -->
        <div class="table-page-search-wrapper" style="position: relative">
          <div class="search-wrapper-btn">
            <a-button type="link" @click="show = !show">
              <span v-if="!show">展开
                <a-icon type="down" />
              </span>
              <span v-else>收起
                <a-icon type="up" />
              </span>
            </a-button>
          </div>
          <a-form-model :label-col="labelCol" :wrapper-col="wrapperCol" @keyup.enter.native="onQuery">
            <div class="mode_item">
              <div class="mode_item_div">
                <a-form-model-item label="特殊人员类型">
                  <a-select v-model="pageFilter.specialPersonType" placeholder="请选择" allowClear>
                    <a-select-option value="1">病重</a-select-option>
                    <a-select-option value="2">精神疾病</a-select-option>
                  </a-select>
                </a-form-model-item>
              </div>
              <div class="mode_item_div">
                <a-form-model-item label="申请人">
                  <a-input v-model="pageFilter.createBy" placeholder="请输入" />
                </a-form-model-item>
              </div>
            </div>
            <div class="mode_item" v-show="show">
              <div class="mode_item_div">
                <a-form-model-item label="申请管控免除类型">
                  <a-select v-model="pageFilter.controlExemptionType" placeholder="请选择">
                    <a-select-option value="">不限</a-select-option>
                    <a-select-option value="1">打卡免签</a-select-option>
                    <a-select-option value="2">免尿液检测</a-select-option>
                    <a-select-option value="3">定期访谈</a-select-option>
                    <a-select-option value="4">定期报告</a-select-option>
                  </a-select>
                </a-form-model-item>
              </div>
              <div class="mode_item_div">
                <a-form-model-item label="申请管控类型">
                  <a-select v-model="pageFilter.controlType" placeholder="请选择">
                    <a-select-option value="">不限</a-select-option>
                    <a-select-option value="1">毛发检测</a-select-option>
                  </a-select>
                </a-form-model-item>
              </div>
              <div class="mode_item_div mode_item_flex">
                <a-form-model-item label="状态">
                  <a-radio-group v-model="pageFilter.status" @change="onStatusChange">
                    <a-radio value="">全部</a-radio>
                    <a-radio value="1">待审批</a-radio>
                    <a-radio value="4">已驳回</a-radio>
                    <a-radio value="3">已通过</a-radio>
                  </a-radio-group>
                </a-form-model-item>
              </div>
            </div>
            <div class="btnBox">
              <a-form-model-item :wrapper-col="{ offset: 0 }" style="margin-bottom: 0">
                <a-button type="primary" @click="onQuery"> 查询 </a-button>
                <a-button style="margin-left: 10px" @click="onResetForm"> 重置 </a-button>
              </a-form-model-item>
            </div>
          </a-form-model>
        </div>
      </a-card>
      <a-card :bordered="false">
        <!-- 操作按钮区域 -->
        <div class="table-operator">
          <a-button type="primary" @click="onInput()">特殊人群审批申请</a-button>
          <!-- <a-button @click="aaa">测试</a-button> -->
        </div>
        <!-- 表格展示 -->
        <div class="table-page-content">
          <z-table ref="table" rowKey="id" :showAlert="false" :showSelection="false" :loading="loading"
            :columns="columns" :dataSource="pageData" @change="onTableChange">
            <template slot="specialPersonType" slot-scope="text">
              <span v-if="text == '1'">病重</span>
              <span v-if="text == '2'">精神疾病</span>
            </template>
            <template slot="controlExemptionType" slot-scope="text">
              <span v-if="text && text.indexOf('1') != -1">打卡签到；</span>
              <span v-if="text && text.indexOf('2') != -1">常规尿检；</span>
              <span v-if="text && text.indexOf('3') != -1">突击尿检；</span>
              <span v-if="text && text.indexOf('4') != -1">定期访谈</span>
              <!-- <j-ellipsis :value="text" :length="10"/> -->
            </template>
            <template slot="controlType" slot-scope="text">
              <span v-if="text == '1'">毛发检测</span>
              <!-- <span v-if="text == undefined">暂无检测</span> -->
            </template>
            <template slot="status" slot-scope="text">
              <span v-if="text == '1'" style="color:#108EE9">待审批</span>
              <span v-if="text == '2'" style="color:#108EE9">审批中</span>
              <span v-if="text == '3'" style="color:#27BF44">已通过</span>
              <span v-if="text == '4'" style="color:#D9001B">已驳回</span>
              <span v-if="text == '5'" style="color:#999">已撤销</span>
            </template>
            <template slot="supportMaterials" slot-scope="text">
              <j-upload v-model="text"></j-upload>
            </template>
            <!--操作-->
            <template slot="action" slot-scope="text, record">
              <template v-if="record.status == '1'">
                <a-button @click="onCYX(record)" type="link" style="padding: 0">催一下</a-button>
                <a-divider type="vertical" />
                <a-button @click="onCX(record)" type="link" style="padding: 0">撤销申请</a-button>
                <a-divider type="vertical" />
              </template>
              <template v-if="record.status == '4' || record.status == '5'">
                <a-button @click="onInput(record)" type="link" style="padding: 0">重新提交</a-button>
                <a-divider type="vertical" />
                <a-button @click="onDelete(record)" type="link" style="padding: 0">删除</a-button>
                <a-divider type="vertical" />
              </template>
              <a-button @click="onDetail(record)" type="link" style="padding: 0">查看</a-button>
            </template>
          </z-table>
        </div>
        <AddModal ref="addModalId" @ok="onQuery" />
      </a-card>
    </a-col>
  </a-row>
</template>

<script>
import * as specialApi from '@/api/sjsk/specialPopul.js'
import { getUrge, cancel } from '@/api/sjsk/flowService'
import AddModal from './modules/AddModal'
import DepartTree from '@/views/sjsk/modules/departTree'
export default {
  components: {
    AddModal,
    DepartTree,
  },
  data() {
    return {
      labelCol: { span: 8 },
      wrapperCol: { span: 16 },
      show: false,
      loading: false,
      visible: false,
      reloading: false,
      treeDatas: [],
      toggle: true,
      columns: [
        {
          title: '序号',
          dataIndex: 'order',
          width: 50,
          align: 'center',
          customRender: (text, record, index) =>
            `${(this.pageFilter.pageNo - 1) * this.pageFilter.pageSize + (index + 1)}` //序号分页后连续
        },
        {
          title: '人员姓名',
          dataIndex: 'name',
          align: 'center',
          width: 65
        },
        {
          title: '身份证号',
          dataIndex: 'identification',
          align: 'center',
        },
        {
          title: '特殊人员类型',
          dataIndex: 'specialPersonType',
          align: 'center',
          width: 95,
          scopedSlots: { customRender: 'specialPersonType' },
        },
        {
          title: '申请管控免除类型',
          dataIndex: 'controlExemptionType',
          align: 'center',
          // width: 300,
          // scopedSlots: { customRender: 'controlExemptionType'},
          customRender: (text, record, index) => {
            const texts1 = text && text.indexOf('1') != -1 ? '打卡签到；' : ''
            const texts2 = text && text.indexOf('2') != -1 ? '常规尿检；' : ''
            const texts3 = text && text.indexOf('3') != -1 ? '突击尿检；' : ''
            const texts4 = text && text.indexOf('4') != -1 ? '定期访谈' : ''
            const texts = texts1 + texts2 + texts3 + texts4
            return (
              <j-ellipsis value={texts} length={6} />
            )
          }
          // customRender:(text) => (<j-ellipsis value={text} length={10}/>)

        },
        {
          title: '申请管控类型',
          dataIndex: 'controlType',
          align: 'center',
          width: 95,
          scopedSlots: { customRender: 'controlType' },
        },
        {
          title: '证明材料',
          dataIndex: 'supportMaterials',
          align: 'center',
          scopedSlots: { customRender: 'supportMaterials' },
        },
        {
          title: '状态',
          dataIndex: 'status',
          align: 'center',
          width: 50,
          scopedSlots: { customRender: 'status' },
        },
        {
          title: '操作',
          width: 180,
          align: 'center',
          dataIndex: 'action',
          scopedSlots: { customRender: 'action' },
        },
      ],
      pageFilter: {
        pageNo: 1,
        pageSize: 10,
      },
      pageData: {},
      departmentId: ""
    }
  },
  created() {

  },
  async mounted() {
    // this.onQuery()
  },
  // watch: {
  //   // 组织机构树-联动筛选人员列表
  //   'pageFilter.departmentId'(newVal, oldVal) {
  //     this.onQuery()
  //   }
  // },
  methods: {
    // aaa(text){
    //   if(text.indexOf('3') != -1){return 'aaa'}
    // },
    onQuery() {
      this.pageFilter.pageNo = 1
      // console.log(this.pageFilter);
      this.refreshTable()
    },
    onResetForm() {
      this.pageFilter = {
        pageNo: 1,
        pageSize: 10,
        departmentId: this.departmentId
      }
      this.refreshTable()
    },
    onStatusChange() {

    },
    getStr(text) {
      // if()
    },
    onTableChange(pagination, pageFilter, sorter) {
      let keyMap = { currentPage: 'pageNo' }
      let paginations = Object.keys(pagination).reduce((newData, key) => {
        let newKey = keyMap[key] || key
        newData[newKey] = pagination[key]
        return newData
      }, {})
      this.pageFilter = Object.assign({}, this.pageFilter, paginations)
      this.refreshTable()
    },
    refreshTable() {
      this.loading = true
      specialApi
        .viewPopul(this.pageFilter)
        .then((res) => {
          if (res.success) {
            // console.log(res);
            this.pageData = res.result ? res.result : {}
            console.log(this.pageData);
            this.loading = false
          } else {
            this.loading = false
          }
        })
        .catch((e) => {
          this.loading = false
          this.$message.warn('请求失败！')
        })
    },
    onInput(record) {
      this.$refs.addModalId.show(record)
    },
    //跳转到流程审批
    onDetail(record) {
      this.$router.push({
        path: `/examine/details/25/${record.id}`
      })
    },
    onDelete(record) {
      let that = this;
      this.$confirm({
        title: `确定要删除吗?`,
        okText: "确认",
        okType: "danger",
        cancelText: "取消",
        onOk() {
          specialApi.specialDelete({ id: record.id }).then((res) => {
            if (res.success) {
              that.$message.success(res.message);
              that.onQuery()
            } else {
              that.$message.warning(res.message);
            }
          });
        }
      });
    },
    onCYX(record) {
      getUrge({ id: record.id, type: '25' }).then((res) => { //特殊人群处置审批类型25
        if (res.success) {
          this.$message.success(res.message);
          this.onQuery()
        } else {
          this.$message.warning(res.message);
        }
      });
    },
    onCX(record) {
      let that = this;
      this.$confirm({
        title: `还在审批中，确定要撤销吗?`,
        okText: "确认",
        okType: "danger",
        cancelText: "取消",
        onOk() {
          cancel({ taskId: record.id, type: '25' }).then((res) => { //特殊人群处置审批类型25
            if (res.success) {
              that.$message.success(res.message);
              that.onQuery()
            } else {
              that.$message.warning(res.message);
            }
          });
        }
      });
    },
    getEllipsisValue() {

    },
    /** 重新加载组件 */
    reload() {
      this.reloading = true
      this.$nextTick(() => (this.reloading = false))
    },
    // 选中组织架构树，赋值到人员列表搜索框
    getTreeData(datas, id) {
      if (id != undefined && id != null && id != "") {
        this.departmentId = id
        this.$set(this.pageFilter, 'departmentId', id)
        this.onQuery()
      }
    },
    toggleBool(bool) {
      console.log(bool)
      this.toggle = bool
    }
  },
}
</script>
<style lang="less" scoped>
.mode_item {
  display: flex;
  border-bottom: 1px #dadada dashed;
  // border-bottom: 1px pink dashed;

  .mode_item_div {
    width: 29%;
    padding: 5px 0;

    .ant-form-item {
      margin-bottom: 0;
    }

    /deep/ .ant-col-8 {
      width: 43%;
    }

    /deep/ .ant-col-16 {
      width: 57%;
    }
  }

  &>* {
    width: 100%;
    margin-bottom: 0;
    padding: 10px 0;
  }
}

.mode_item_div1 {
  // width: 49% !important;

  /deep/ .ant-col-8 {
    width: 25% !important;
  }
}

.mode_item_flex {
  width: 65% !important;
  position: absolute;
  right: -18%;

  /deep/ .ant-col-8 {
    width: 18.5% !important;
  }
}

.search-wrapper-btn {
  position: absolute;
  right: 15%;
  top: 9px;
  z-index: 100;
}

.btnBox {
  position: absolute;
  right: 0;
  top: 5px;
  z-index: 120;
}

/deep/.table-page-content {
  .ant-upload {
    display: none;
  }

  .ant-upload-list-item {
    a {
      width: 200px;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
      cursor: pointer;
      display: inline-block;
      padding: 0;
    }

    i {
      display: none;
    }
  }

  .ant-upload-list-item-card-actions {
    display: none;
  }
}

@import '~@assets/less/common.less';
</style>
